package com.m4f.cityclient.api.service.impl;

import java.util.List;
import java.util.logging.Logger;

import com.google.api.client.json.GenericJson;
import com.google.api.client.util.Key;
import com.m4f.cityclient.api.exception.M4FCityClientException;
import com.m4f.cityclient.api.models.ApplicationCity;
import com.m4f.cityclient.api.service.ifc.M4FApplicationApiService;

/**
 * @author David Basoko
 */
public class M4FApplicationApiServiceImpl extends M4FBaseApiService implements M4FApplicationApiService {
	private static final Logger LOGGER = Logger.getLogger(M4FApplicationApiServiceImpl.class.getName());
	
	private String m4fscApplicationsOfUserUrl;
	private String m4fscApplicationInfoUrl;
	
	@Override
	public List<ApplicationCity> getApplicationsOfUser() throws M4FCityClientException {
		
		Applications applications = this.getData(getM4fscApplicationsOfUserUrl(), Applications.class);
		
		return applications.getApplications();
	}
	
	@Override
	public ApplicationCity getApplicationInfo(Long applicationId) throws M4FCityClientException {
		return this.getData(getM4fscApplicationInfoUrl(), ApplicationCity.class, 
				new String[]{"applicationId"}, 
				new Object[]{applicationId});
	}

	public String getM4fscApplicationsOfUserUrl() {
		return m4fscApplicationsOfUserUrl;
	}

	public void setM4fscApplicationsOfUserUrl(String m4fscApplicationsOfUserUrl) {
		this.m4fscApplicationsOfUserUrl = m4fscApplicationsOfUserUrl;
	}

	public String getM4fscApplicationInfoUrl() {
		return m4fscApplicationInfoUrl;
	}

	public void setM4fscApplicationInfoUrl(String m4fscApplicationInfoUrl) {
		this.m4fscApplicationInfoUrl = m4fscApplicationInfoUrl;
	}
	
	public static class Applications extends GenericJson {
		
		@Key("applications")
		private List<ApplicationCity> applications;

		public List<ApplicationCity> getApplications() {
			return applications;
		}

		public void setApplications(List<ApplicationCity> applications) {
			this.applications = applications;
		}
	}
}
